﻿
@{
    ViewBag.Title = "testPay";
    Layout = "~/Views/Shared/_MyLayout.cshtml";
}

@section head{


    @Scripts.Render("~/bundles/jquery")
    <script src="~/Scripts/bootstrap.js"></script>


}
<h2>testPay</h2>

<div style="background-color:limegreen;" onclick="funcOrder()">
    <h3 style="text-align:center;">点击生成预付订单</h3>
</div>

<div id="pay" style="display:none;background-color:limegreen;" onclick="callpay()">
    <h3 style="text-align:center;">点击付款</h3>
</div>
<p id="apiparam"></p>

<script type="text/javascript">
    var wxJsApiParam = "";
    function funcOrder() {
        $.ajax({
            type: "POST",
            url: "/WxRequest/TestPay",
            async: false,
            data: { "OrderId": "10010" },
            success: function (msg) {
                if (msg.err == "ok") {
                    //正确返回，执行操作                    
                    wxJsApiParam = msg.Param;
                    alert("生成订单成功了");
                    $("#pay").css("display", "block");
                    $("#apiparam").text(msg.Param);

                } else {
                    alert("订单提交失败，请联系酒店前台");
                    return;
                }
            }
        });
    }
    function jsApiCall() {
        WeixinJSBridge.invoke(
            'getBrandWCPayRequest',
            $.parseJSON(wxJsApiParam),//josn串
            function (res) {
                WeixinJSBridge.log(res.err_msg);
                alert(res.err_code + res.err_desc + res.err_msg);
            }
        );
    }
    function callpay() {
        if (typeof WeixinJSBridge == "undefined") {
            if (document.addEventListener) {
                document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
            } else if (document.attachEvent) {
                document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
            }
        } else {
            jsApiCall();
        }
    }



</script>

